import java.util.Scanner;

public class Boom {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            scanner.nextLine();

            char[][] map = new char[n][m];

            for (int i = 0; i < n; i++) {
                String row = scanner.nextLine();
                map[i] = row.toCharArray();
            }

            int maxEnemies = findMaxEnemies(map);
            System.out.println(maxEnemies);
        }

        scanner.close();
    }

    private static int findMaxEnemies(char[][] map) {
        int n = map.length;
        int m = map[0].length;
        int maxEnemies = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (map[i][j] == '.') {
                    int enemies = countEnemies(map, i, j);
                    maxEnemies = Math.max(maxEnemies, enemies);
                }
            }
        }

        return maxEnemies;
    }

    private static int countEnemies(char[][] map, int row, int col) {
        int n = map.length;
        int m = map[0].length;
        int count = 0;

        // Up
        for (int i = row - 1; i >= 0 && map[i][col] != '#'; i--) {
            if (map[i][col] == 'G') {
                count++;
            }
        }

        // Down
        for (int i = row + 1; i < n && map[i][col] != '#'; i++) {
            if (map[i][col] == 'G') {
                count++;
            }
        }

        // Left
        for (int j = col - 1; j >= 0 && map[row][j] != '#'; j--) {
            if (map[row][j] == 'G') {
                count++;
            }
        }

        // Right
        for (int j = col + 1; j < m && map[row][j] != '#'; j++) {
            if (map[row][j] == 'G') {
                count++;
            }
        }

        return count;
    }
}